function ajaxLoading(msg) {
    $("<div class=\"datagrid-mask\"></div>").css({
        display: "block",
        width: "100%",
        height: $(window).height()+1000
    }).appendTo("body");
    $(".datagrid-mask").attr("z-index", 99999);
    $("<div class=\"datagrid-mask-msg\" style='font-size: 12px;'></div>").html(msg).appendTo("body").css({
        display: "block",
        left: ($(document.body).outerWidth(true) - 190) / 2,
        top: ($(window).height() - 45) / 2
    });
}

function ajaxLoadEnd() {
    $(".datagrid-mask").remove();
    $(".datagrid-mask-msg").remove();
}

function initPagination(totalPage, pageSize) {
    var tmp = Math.ceil(totalPage / pageSize);
    var tmpMap = [];
    for (var i = 1; i <= tmp; i++) {
        var start = (i - 1) * pageSize;
        var end = start + pageSize;
        tmpMap.push({start: start, end: end});
    }
    return tmpMap;
}

function GetPercent(num, total) {
    /// <summary>
    /// 求百分比
    /// </summary>
    /// <param name="num">当前数</param>
    /// <param name="total">总数</param>
    num = parseFloat(num);
    total = parseFloat(total);
    if (isNaN(num) || isNaN(total)) {
        return "-";
    }
    return total <= 0 ? "0%" : (Math.round(num / total * 10000) / 100.00)+"%";
}

function GetPercent2(num, total) {
    /// <summary>
    /// 求百分比
    /// </summary>
    /// <param name="num">当前数</param>
    /// <param name="total">总数</param>
    num = parseFloat(num);
    total = parseFloat(total);
    if (isNaN(num) || isNaN(total)) {
        return "-";
    }
    return total <= 0 ? "0" : (Math.round(num / total * 10000) / 100.00);
}

function GetAge(identityCard) {
    var len = (identityCard + "").length;
    if (len == 0) {
        return 0;
    } else {
        if ((len != 15) && (len != 18))//身份证号码只能为15位或18位其它不合法
        {
            return 0;
        }
    }
    var strBirthday = "";
    if (len == 18)//处理18位的身份证号码从号码中得到生日和性别代码
    {
        strBirthday = identityCard.substr(6, 4) + "/" + identityCard.substr(10, 2) + "/" + identityCard.substr(12, 2);
    }
    if (len == 15) {
        strBirthday = "19" + identityCard.substr(6, 2) + "/" + identityCard.substr(8, 2) + "/" + identityCard.substr(10, 2);
    }
    //时间字符串里，必须是“/”
    var birthDate = new Date(strBirthday);
    var nowDateTime = new Date();
    var age = nowDateTime.getFullYear() - birthDate.getFullYear();
    //再考虑月、天的因素;.getMonth()获取的是从0开始的，这里进行比较，不需要加1
    if (nowDateTime.getMonth() < birthDate.getMonth() || (nowDateTime.getMonth() == birthDate.getMonth() && nowDateTime.getDate() < birthDate.getDate())) {
        age--;
    }
    //alert(age);
    return age;
}



let lastDHReg = /,$/gi;

function cutLastDH(str) {
    str = str.replace(lastDHReg, "");
    return str;
}

function getCheckboxValue(checkBoxName, d) {
    let testCheckBoxValues = $("input[name='" + checkBoxName + "']:checked");
    let m = "";
    $.each(testCheckBoxValues, function () {
        m += $(this).val() + ",";
    });
    d[checkBoxName] = cutLastDH(m);
    //console.log("d:", d);
}
function changeTab(id) {
    let _id="li_"+id;
    $("#"+_id).addClass("active").siblings().removeClass("active");
    $("#"+id).addClass("active tab-pane").siblings().removeClass("active");
}
function afterUpdateFormData(resp,formType) {
    if (resp.code == 0) {
        toastr.success(resp.msg,'',{"positionClass": "toast-top-center"});
        window.localStorage.setItem("currentTab",formType);
        setTimeout(function () {
            window.location.reload();
        }, 500);
    }else{
        toastr.warning(resp.msg, '提示', {
            "progressBar": true,
            "positionClass": "toast-top-center",
            "timeOut": "5000",
            "closeButton":true
        });
    }
}
